package com.jerry.template.module.mainpage.find.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jerry.template.R;
import com.jerry.template.base.BaseApplication;
import com.jerry.template.base.BaseViewHolder;
import com.jerry.template.base.MyBaseAdapter;
import com.jerry.template.module.mainpage.find.entity.BannerList;
import com.jerry.template.views.GlideCircleTransform;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import butterknife.BindView;

/**
 * Created by chenhuan on 2016/5/14.
 */
public class BannerListAdapter extends MyBaseAdapter<BannerList.DataBean1.DataBean> {
    private List<BannerList.DataBean1.DataBean> data;
    private ImageLoader imageLoader;
    private Context context;
    private static final int TYPEE_MUTIPLE_IMAGE = 1;
    private static final int TYPE_SINGLE_IMAGE = 2;

    public BannerListAdapter(Context context, List<BannerList.DataBean1.DataBean> data) {
        super(context, data);
        this.data = data;
        this.context = context;
        imageLoader = BaseApplication.getApplication().getImageLoader();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_banner_list_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        return new ViewHodler();
    }

   /* @Override
    public int getItemViewType(int position){
        BannerList.DataBean1.DataBean.GroupBean group = getItem(position).getGroup();

        if(group.getLarge_image()!=null && group.getLarge_image().getUrl_list() == null){
            return TYPE_SINGLE_IMAGE;
        }else if(group.getLarge_image().getUrl_list()!=null){
            return TYPEE_MUTIPLE_IMAGE;
        }
        return TYPE_SINGLE_IMAGE;
    }
*/
   /* @Override
    public int getViewTypeCount(){
        return 3;
    }*/

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {
        ViewHodler holder = (ViewHodler) viewHolder;

        Log.d("BannerListAdapter", data.get(holder.position).getGroup().getUser().getName());
        try {
            if (data.get(holder.position).getGroup().getUser() != null &&
                    data.get(holder.position).getGroup() != null) {
                BannerList.DataBean1.DataBean.GroupBean.UserBean user = data.get(holder.position).getGroup().getUser();
                BannerList.DataBean1.DataBean.GroupBean group = data.get(holder.position).getGroup();
                //设置用户头像和用户名
                String avatar_url = user.getAvatar_url();
                //imageLoader.displayImage(avatar_url,holder.userHeadImage);
                Glide.with(context).load(avatar_url).transform(new GlideCircleTransform(context)).into(holder.userHeadImage);
                holder.userName.setText(user.getName());

                //设置内容
                if (group.getText() != null) {
                    holder.content.setText(group.getText());
                }
                //设置点赞、分享、评论等
                holder.upCount.setText(group.getDigg_count() + "");
                holder.downCount.setText(group.getBury_count() + "");
                holder.commentCount.setText(group.getComment_count() + "");
                holder.shareCount.setText(group.getShare_count() + "");

                //设置内容图片
           /* imageLoader.displayImage(group.getLarge_image().getUri(),holder.image);

            int type = getItemViewType(holder.position);
            if(type == TYPE_SINGLE_IMAGE){
                String contentUrl = group.getLarge_image().getUri();
                imageLoader.displayImage(contentUrl,holder.image);
            }else if(type == TYPEE_MUTIPLE_IMAGE){
                List<BannerList.DataBean1.DataBean.GroupBean.LargeImageBean.UrlListBean> url_list = group.getLarge_image().getUrl_list();
                BannerGridViewAdapter adapter = new BannerGridViewAdapter(url_list,context);
                holder.item_grid.setAdapter(adapter);
            }*/

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static class ViewHodler extends BaseViewHolder {
        @BindView(R.id.dapei_user_head)
        ImageView userHeadImage;
        @BindView(R.id.dapei_user_head_user_name)
        TextView userName;
        @BindView(R.id.dapei_content)
        TextView content;

        @BindView(R.id.dapei_image)
        ImageView image;
        @BindView(R.id.dapei_favourite_count)
        TextView upCount;
        @BindView(R.id.dapei_go_detail_count)
        TextView downCount;
        @BindView(R.id.dapei_comment_count)
        TextView commentCount;

        @BindView(R.id.dapei_item_grid)
        GridView item_grid;

        @BindView(R.id.dapei_share_count)
        TextView shareCount;
    }
}

